
package JET.ImageUtils;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import javax.swing.ImageIcon;

/**
 *
 * @author raos
 */
public class ImageUtils {


    /**
     * Loads ImageIcon from specified project resource file.
     *
     * @param path
     * @return ImageIcon object loaded from specified resource file.
     */
    public static ImageIcon loadImageIconFromResources(String path) {
        try {
            InputStream is = ImageUtils.class.getResourceAsStream(path);
            //StringBuffer sb = new StringBuffer();
            ByteArrayOutputStream baos = new ByteArrayOutputStream(is.available());
            int ch = 0;
            while ( (ch=is.read()) != -1)
                //sb.append(ch);
                baos.write(ch);

            return new ImageIcon(baos.toByteArray());
        } catch(Exception e) {}

        return null;
    }
}
